#pragma once
#include <iostream>
#include<string>
#include <unistd.h>
#include <memory>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cerrno>
#include <cstring>
#include <functional>
#include <sys/wait.h>
#include<thread>
#include <signal.h>

using namespace std;

class Inet_addr//套接字相关信息
{
public:
    Inet_addr() {}

    Inet_addr(const struct sockaddr_in &clients)
        // : _si(clients), _ip(inet_ntoa(clients.sin_addr)), _port(ntohs(clients.sin_port))//inet_ntoa存在线程安全问题
        : _si(clients),  _port(ntohs(clients.sin_port))
    {
        char buffer[77];
        inet_ntop(AF_INET,&clients.sin_addr,buffer,sizeof(buffer));//1.网络转本机 2.4字节ip转字符串ip
        _ip=buffer;
    }
    void print_client_info(const char *buffer)
    {
        cout << "[port:" << _port << " "
             << "ip:" << _ip << "]";
        cout << "client says:" << buffer << endl;
    }
    bool operator==(const Inet_addr &com)
    {
        return _ip == com._ip && _port == com._port;
    }
    const struct sockaddr_in &addr()
    {
        return _si;
    }
    const string &ip()
    {
        return _ip;
    }
    const in_port_t &port()
    {
        return _port;
    }
    ~Inet_addr()
    {
    }

private:
    struct sockaddr_in _si;
    string _ip;
    in_port_t _port;
};